/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingResourceManageInfo: {
                housekeepingResources: [],
                total: 0,
                records: 1,
                moreCondition: false,
                resId: '',
                resourceStoreTypes: [],
                conditions: {
                    resTypeId: '',
                    resTypeName: '',
                    resName: '',
                    supplierName: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that._listHousekeepingResources(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listResourceStoreTypes(1, 50);
        },
        _initEvent: function () {
            vc.on('housekeepingResourceManage', 'listHousekeepingResource', function (_param) {
                $that._listHousekeepingResources(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingResources(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingResources: function (_page, _rows) {
                $that.housekeepingResourceManageInfo.conditions.page = _page;
                $that.housekeepingResourceManageInfo.conditions.row = _rows;
                let param = {
                    params: $that.housekeepingResourceManageInfo.conditions
                };
                param.params.resName = param.params.resName.trim();
                param.params.supplierName = param.params.supplierName.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingResource/queryHousekeepingResource',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingResourceManageInfo.total = _json.total;
                        $that.housekeepingResourceManageInfo.records = _json.records;
                        $that.housekeepingResourceManageInfo.housekeepingResources = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingResourceManageInfo.records,
                            dataCount: $that.housekeepingResourceManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listHousekeepingTypes: function (_page, _rows) {
                var param = {
                    params: {
                        page: _page,
                        row: _rows
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingType.queryHousekeepingType',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询方法
            _listResourceStoreTypes: function (_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送post请求
                vc.http.apiGet(
                    'resourceStoreType.listResourceStoreTypes',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingResourceManageInfo.resourceStoreTypes = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddHousekeepingResourceModal: function () {
                vc.emit('addHousekeepingResource', 'openAddHousekeepingResourceModal', {});
            },
            _openEditHousekeepingResourceModel: function (_housekeepingResource) {
                vc.emit('editHousekeepingResource', 'openEditHousekeepingResourceModal', _housekeepingResource);
            },
            _openDeleteHousekeepingResourceModel: function (_housekeepingResource) {
                vc.emit('deleteHousekeepingResource', 'openDeleteHousekeepingResourceModal', _housekeepingResource);
            },
            //查询
            _queryHousekeepingResourceMethod: function () {
                $that._listHousekeepingResources(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetHousekeepingResourceMethod: function () {
                $that.housekeepingResourceManageInfo.conditions.resTypeId = "";
                $that.housekeepingResourceManageInfo.conditions.resName = "";
                $that.housekeepingResourceManageInfo.conditions.supplierName = "";
                $that._listHousekeepingResources(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openhousekeepingFeeConfigManage: function (_housekeepingResource) {
                //跳转到浏览器
                vc.jumpToPage('/#/pages/housekeeping/housekeepingFeeConfigManage?configId=' + _housekeepingResource.configId);
            },
            _moreCondition: function () {
                if ($that.housekeepingResourceManageInfo.moreCondition) {
                    $that.housekeepingResourceManageInfo.moreCondition = false;
                } else {
                    $that.housekeepingResourceManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
